package com.yj.cloudnote.service.Impl;

import com.yj.cloudnote.dao.ShareMapper;
import com.yj.cloudnote.model.Page;
import com.yj.cloudnote.model.Share;
import com.yj.cloudnote.model.User;
import com.yj.cloudnote.service.ShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class ShareServiceImpl implements ShareService {
    @Autowired
    private ShareMapper shareMapper;

    @Override
    public boolean insertNewShare(Share share) {
        int res = shareMapper.insertSelective(share);
        if (res >= 1) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Share getShareByUserFile(String username, int file_id) {
        HashMap<String,Object> params = new HashMap<String,Object>();
        params.put("username",username);
        params.put("file_id",file_id);
        Share share = shareMapper.selectByUsernameFileID(params);
        return share;
    }

    @Override
    public Share getShareById(int share_id) {
        return shareMapper.selectByPrimaryKey(share_id);
    }

    @Override
    public void complaint(Share share) {
        shareMapper.updateByPrimaryKeySelective(share);
    }

    @Override
    public List<Share> getComplaintsByPage(Page page) {
        HashMap<String,Object> params = new HashMap<String,Object>();
        params.put("start",page.getStart());
        params.put("end",page.getEnd());
        return shareMapper.selectComplaintsByPage(params);
    }

    @Override
    public int getComplaintsCount() {
        return shareMapper.getComplaintsCount();
    }

    @Override
    public void deleteShare(int shareId) {
        shareMapper.deleteByPrimaryKey(shareId);
    }

}
